﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAO;
using DVO;

public partial class CheckDocument : System.Web.UI.Page
{
    public string username = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(Page.User.Identity.Name))
        {
            username = Page.User.Identity.Name;

            if (IsPostBack == false)
            {
                LoadData();
                LoadAuthor();
            }
        }
        else
        {
            Response.Redirect("Login.aspx");
        }
    }

    #region "LoadData"
    private void LoadData()
    {
        string id = txtDocId.Text.Trim();
        string docname = txtDocName.Text.Trim();
        string author = ddlAuthor.SelectedValue.ToString();
        BLL_Document ObjBLL = new BLL_Document();
        List<ins_Document_SearchResult> ObjList = new List<ins_Document_SearchResult>();
        ObjList = ObjBLL.Document_SearchCheck(id,docname,author).ToList();
        grid.DataSource = ObjList;
        grid.DataBind();

    }

    private void LoadAuthor()
    {
        BLL_Member ObjBLL = new BLL_Member();
        List<ins_Member_SelectLevelResult> Objlist = new List<ins_Member_SelectLevelResult>();
        try
        {
            Objlist = ObjBLL.Level_Select(1).ToList();
            ddlAuthor.DataSource = Objlist;
            ddlAuthor.DataTextField = "UserName";
            ddlAuthor.DataValueField = "UserName";
            ddlAuthor.DataBind();
        }
        catch (Exception ex) 
        {

            Common.WriteLog(ex.Message, ex.StackTrace);
        }
    }
    #endregion

    public string GetStatus(string Status)
    {
        if (Status == "0")
            return "Chờ kiểm duyệt";
        else if (Status == "1")
            return "Đã duyệt";
        else if (Status == "2")
            return "Chờ phê duyệt";
        else if (Status == "3")
            return "Chỉnh sửa";
        return "";
    }
    public string KiemDuyet(string Status, string id)
    {
        
        if (Status == "0")
            return "<a" + " href='TestDocument.aspx?WId=" + id + "'  onmouseout='UnTip()' onmouseover=\"Tip('XEM KIỂM DUYỆT TÀI LIỆU NHÂN VIÊN')\">Kiểm duyệt tài liệu</a>";
        else 
            return "";
    }
    protected void grid_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grid.PageIndex = e.NewPageIndex;
        LoadData();
    }
}
